﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsTonHangKyGoi
    {
        private string mKhoaDoiTuong = "";
        private string mKhoaDonVi = "";
        private string mKhoaNhanVien = "";
        private string mNamThang = "";

        public void CapNhatLaiSoLieu()
        {
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_CapNhatTonHangKyGoi", commandParameters);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                ProjectData.ClearProjectError();
            }
        }

        public void CapNhatTonHangKyGoi(string pKhoaHangHoa, string pSoSeri, string pSoLoHang, string pHanSuDung, double pSoLuongXuat, double pTriGiaXuat, double pSoLuongTonCuoi, double pTriGiaTonCuoi)
        {
            IDataParameter[] commandParameters = new IDataParameter[12];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[2] = DBHelper.createParameter("@KhoaNhanVien", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVien);
                commandParameters[3] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[4] = DBHelper.createParameter("@KhoaHangHoa", DbType.Int64, ParameterDirection.Input, pKhoaHangHoa);
                commandParameters[5] = DBHelper.createParameter("@SoSeri", DbType.Int64, ParameterDirection.Input, pSoSeri);
                commandParameters[6] = DBHelper.createParameter("@SoLoHang", DbType.Int64, ParameterDirection.Input, pSoLoHang);
                commandParameters[7] = DBHelper.createParameter("@HanSuDung", DbType.Int64, ParameterDirection.Input, pHanSuDung);
                commandParameters[8] = DBHelper.createParameter("@SoLuongXuat", DbType.Date, ParameterDirection.Input, pSoLuongXuat);
                commandParameters[9] = DBHelper.createParameter("@TriGiaXuat", DbType.Date, ParameterDirection.Input, pTriGiaXuat);
                commandParameters[10] = DBHelper.createParameter("@SoLuongTonCuoi", DbType.Date, ParameterDirection.Input, pSoLuongTonCuoi);
                commandParameters[11] = DBHelper.createParameter("@TriGiaTonCuoi", DbType.Date, ParameterDirection.Input, pTriGiaTonCuoi);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "Sp_CapNhatTonKyGoi", commandParameters);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                ProjectData.ClearProjectError();
            }
        }

        public DataTable GetData()
        {
            DataTable table;
            try
            {
                string commandText = " SELECT T.KhoaHangHoa, HH.Ma, HH.Ten" + modGeneral.H_LANGUAGE + " As TenHang, DVT.Ten" + modGeneral.H_LANGUAGE + " As DonViTinh, T.SoLoHang, dbo.Char2Date(T.HanSuDung) As HanSuDung, T.SoLuongTonDau, T.SoLuongNhap, T.SoLuongXuat,  T.SoLuongTonCuoi, T.TriGiaTonDau, T.TriGiaNhap, T.TriGiaXuat, T.TriGiaTonCuoi  FROM BH_TonHangKyGoi T LEFT JOIN DM_HangHoa HH on T.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on HH.KhoaDonViTinh = DVT.Khoa  WHERE T.NamThang ='" + this.mNamThang + "' AND T.KhoaDoiTuong = '" + this.mKhoaDoiTuong + "' AND T.KhoaDonVi = '" + this.mKhoaDonVi + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaNhanVien
        {
            get
            {
                return this.mKhoaNhanVien;
            }
            set
            {
                this.mKhoaNhanVien = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }
    }
}

